<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>应急图书管理系统 - 首页</title>
    <style>
        body {
            font-family: "Helvetica Neue", sans-serif;
            margin: 0;
            background-color: #f9f9f9;
            display: flex;
            flex-direction: column;
            min-height: 100vh;
        }

        .navbar {
            background-color: #2c3e50;
            padding: 15px 30px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            color: white;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }

        .navbar-brand {
            font-size: 24px;
            font-weight: bold;
            text-decoration: none;
            color: white;
        }

        .navbar-menu {
            display: flex;
            gap: 20px;
        }

        .navbar-menu a {
            color: white;
            text-decoration: none;
            font-size: 16px;
            padding: 8px 12px;
            border-radius: 4px;
            transition: background-color 0.3s ease;
        }

        .navbar-menu a:hover {
            background-color: #34495e;
        }

        .navbar-auth {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .navbar-auth span {
            font-size: 16px;
        }

        .auth-btn {
            padding: 8px 16px;
            font-size: 14px;
            cursor: pointer;
            border: none;
            border-radius: 4px;
            background-color: #2196F3;
            color: white;
            transition: background-color 0.3s ease;
            text-decoration: none;
        }

        .auth-btn:hover {
            background-color: #1976D2;
        }

        .content {
            flex: 1;
            padding: 30px;
        }

        h1 {
            text-align: center;
            color: #333;
            margin-bottom: 20px;
        }

        form {
            margin-bottom: 20px;
            display: flex;
            gap: 10px;
            align-items: center;
            flex-wrap: wrap;
            justify-content: center;
        }

        label {
            font-size: 14px;
        }

        input[type="text"],
        input[type="number"],
        input[type="datetime-local"] {
            padding: 5px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        button {
            padding: 6px 14px;
            font-size: 14px;
            cursor: pointer;
            border: none;
            border-radius: 4px;
            background-color: #2c3e50;
            color: white;
            transition: background-color 0.3s ease;
        }

        button:hover {
            background-color: #1a2733;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            background-color: white;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }

        th, td {
            padding: 10px 12px;
            text-align: center;
            border-bottom: 1px solid #ddd;
        }

        th {
            background-color: #f0f0f0;
            color: #333;
        }

        tr:hover {
            background-color: #f5f5f5;
        }

        .action-btn {
            background-color: #2196F3;
            margin: 2px;
            padding: 6px 12px;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        .action-btn:hover {
            background-color: #1976D2;
        }

        .footer {
            background-color: #2c3e50;
            color: white;
            text-align: center;
            padding: 15px;
            font-size: 14px;
        }

        .footer a {
            color: #2196F3;
            text-decoration: none;
        }

        .footer a:hover {
            text-decoration: underline;
        }
    </style>
    <script>
        function viewDetails(id) {
            window.location.href = `/book/public/book/${id}`;
        }

        window.onload = function () {
            const token = localStorage.getItem('token');
            const username = localStorage.getItem('username');
            const userType = localStorage.getItem('userType');
            const authSection = document.getElementById('authSection');
            const menuSection = document.getElementById('menuSection');

            // 动态生成认证区域
            if (token && username) {
                window.location.href = '/book/student/books';
            }

        };

        function logout() {
            localStorage.removeItem('token');
            localStorage.removeItem('userType');
            localStorage.removeItem('userId');
            localStorage.removeItem('username');
            window.location.href = '/user/login';
        }
    </script>
</head>
<body>
<header class="navbar">
    <a href="/" class="navbar-brand">应急图书管理系统</a>
    <div class="navbar-menu" id="menuSection">
        <a href="/toEmergencyInfoPage">科普</a>
        <a href="/book/public/books">图书列表</a>
    </div>
    <div class="navbar-auth" id="authSection">
        <a href="/user/login" class="auth-btn">登录</a>
    </div>
</header>

<main class="content">
    <h1>图书列表</h1>

    <form action="/book/public/books?pageSize=100" method="get">
        <label>书名: <input type="text" name="title" th:value="${param.title}"></label>
        <label>ISBN: <input type="text" name="isbn" th:value="${param.isbn}"></label>
        <button type="submit">查询</button>
    </form>

    <table>
        <thead>
        <tr>
            <th>ID</th>
            <th>书名</th>
            <th>作者</th>
            <th>出版社</th>
            <th>ISBN</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="book : ${books}">
            <td th:text="${book.id}"></td>
            <td th:text="${book.title}"></td>
            <td th:text="${book.author}"></td>
            <td th:text="${book.publisher}"></td>
            <td th:text="${book.isbn}"></td>
            <td th:text="${book.status == 'AVAILABLE' ? '可借' : '已借'}"></td>
            <td>
                <button class="action-btn" type="button" th:onclick="'viewDetails(' + ${book.id} + ')'">详情</button>
            </td>
        </tr>
        <tr th:if="${#lists.isEmpty(books)}">
            <td colspan="7">暂无数据</td>
        </tr>
        </tbody>
    </table>
</main>

<footer class="footer">
    <p>© 2025 应急图书管理系统 | 联系我们: <a href="mailto:support@bookmanagement.com">support@bookmanagement.com</a></p>
</footer>
</body>
</html>